<?php


class CommentsController extends Zend_Controller_Action
{

     protected $_flashMessenger = null;

    function init()
    {
        $usersession = new \Zend_Session_Namespace("usersession");


                              if (!($usersession->general=="generalisimus")){

                                  $this->_redirect('/getin');
                              }

               if ($this->_request->isXmlHttpRequest()) {
                   $this->_helper->layout()->disableLayotu();
               }

               $this->_helper->layout()->setLayout('admin-layout');

               $this->_flashMessenger = new Lib_Flash();
    }

      function indexAction()
    {
        $reviewsManager = new \Managers\Reviews();
        $comments = $reviewsManager->getList();

        $this->view->comments = $comments;
    }

  
        function deleteAction()
    {
        $id = $this->_request->getParam('id');

        $pagesManager = new \Managers\Reviews();
        if($pagesManager->delete($id)) {
            $this->_flashMessenger->addMessage('Comment successfully deleted.', Lib_Flash::NOTICE, Lib_Flash::PRE);
        } else {
            $this->_flashMessenger->addMessage('Comment does not exist.', Lib_Flash::ERROR, Lib_Flash::PRE);
        }
        $this->_redirect('/comments');

    }


      public function grid($qb, $id = '')
    {
        $view = new Zend_View();
        $view->setEncoding('UTF-8');

        $config = new Zend_Config_Ini(APPLICATION_PATH . '/grids/grid.ini', 'production');

        $grid = Bvb_Grid::factory('Table', $config, $id);

        $grid->setEscapeOutput(true);
        $grid->setExport(array('csv', 'excel', 'pdf'));
        $grid->setView($view);
        $grid->setDeleteConfirmationPage(true);
        $gridManager = new \Managers\Grid();
        $em = $gridManager->em();
        $source = new Bvb_Grid_Source_Doctrine2($qb, $em);
        $grid->setSource($source);
        $grid->updateColumn('id', array('hidden' => true));

        $form = new Bvb_Grid_Form();
        $form->setAdd(true)->setEdit(true)->setDelete(true)->setAddButton(true);
        $grid->setForm($form);

        return $grid;
    }



    function editAction(){

        $gridManager=new \Managers\Grid();
        $qb= $gridManager->editComments();
        $grid = $this->grid($qb);

        $this->view->form = $grid->deploy();

         

    }
}
